package org.hyf.inspur.LessonDesin.clear.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//根据业务定义输入和输出的key value的类型
public class WordCountMapper extends Mapper<LongWritable,Text,Text,IntWritable>{
	private final Text text=new Text();
	private final IntWritable num=new IntWritable(1);
	@Override
	protected void map(LongWritable key, Text value,
			Context context)
			throws IOException, InterruptedException {
		String line=value.toString();
		String[] words =line.split(" ");
		for(String word:words){
			text.set(word);
			//System.out.println("hhhh");
			System.out.println("键值对为:"+text+num);
			context.write(text, num);
		}
	}

}
